<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User;
use app\admin\model\ShopList;
class EmployeeController extends BaseController{
	public function waiter(){
		$wherestatus['status']=2;
	    $waiterDate=User::where($wherestatus)->select();
		$this->assign('waiterDate',$waiterDate);
		//dump($waiterDate);
		//店铺信息
		$shopData=ShopList::all();
		$this->assign('shopData',$shopData);
		return $this->fetch();
	}
	public function selwaiter(){
		$page=request()->param('page');
		$limit=request()->param('limit');
		$shop_id=input('param.shop_id');
		$status=input('param.status');
		if($shop_id){
			$wherestatus['shop_id']=$shop_id;
			if($status){
				$wherestatus['status']=$status;
			}else{
				$wherestatus['status']=[2,3];
			}
		}else{
			if($status){
				$wherestatus['status']=$status;
			}else{
				$wherestatus['status']=[2,3];
			}
		}
		$waiterData=User::with(['selshop'=>function($qurey){
			$qurey->field('id,shop_name');
		}])->where($wherestatus)->limit(($page-1)*$limit,$limit)->select()->toArray();
		foreach($waiterData as $k=>$v){
			$waiterData[$k]['selshop'] = $v['selshop']['shop_name'];
		}
		$allcount=count(User::where($wherestatus)->select());
		 $res = [
                'code'=>0,
                'msg'=>'返回成功',
                'count'=>$allcount,
                'data'=>$waiterData
            ];
		return json($res);
	}
	public function waiter_edit(){
		if(request()->isAjax()){
			$whereid['id']=input('param.id');
			$status=input('param.status');
			$data['status']=$status;
			$data['true_name']=input('param.true_name');
			$data['sex']=input('param.sex');;
			$data['phone']=input('param.phone');
			$selres=User::where($whereid)->find();
			$saveres=$selres->save($data);
			if($saveres){
				return true;
			}else{
				return false;
			}
		}
		$id=input('param.id');
		$this->assign('id',$id);
		//查询员工信息
		$employee=User::where('id',$id)->find();
		$this->assign('employee',$employee);
		return $this->fetch();
	}
	//删除服务员信息
	public function waiter_del(){
		$whereid['id']=input('param.id');
		$user=new User();
		$delres=$user->where($whereid)->delete();
		if($delres){
			return true;
		}else{
			return false;
		}
	}
	//分店服务员信息
	public function eachShopWaiter(){
		$whereid['id']=input('param.shop_id');
		$whereid['status']=2;
		$waiterData=User::where($whereid)->select();
		return $waiterData;
	}
	//添加服务员信息
	public function addwaiter(){
		$shopData=ShopList::all();
		$this->assign('shopData',$shopData);
		return $this->fetch();
	}
	//添加服务员信息Ajax
	public function add_waiter(){
		$data['shop_id']=input('param.shop_id');
		$data['phone']=input('param.phone');
		$data['sex']=input('param.sex');
		$data['status']=input('param.status');
		$data['true_name']=input('param.true_name');
		$user=new User();
		$saveres=$user->save($data);
		if($saveres){
			return true;
		}else{
			return false;
		}
	}
	
}
?>